package com.cmccgz.udacs_landlord_webapp.main.unlock;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.orhanobut.logger.Logger;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/18 19:04
 */

public class BluetoothStatusReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.bluetooth.adapter.action.STATE_CHANGED")){
            int intExtra = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
            Intent stateIntent;
            switch (intExtra){
                case BluetoothAdapter.STATE_ON:
                    Logger.e("开启");
                    stateIntent = new Intent(BluetoothLeService.ACTION_STATE_ON);
                    context.sendBroadcast(stateIntent);
                    break;
                case BluetoothAdapter.STATE_OFF:
                    Logger.e("关闭");
                    stateIntent = new Intent(BluetoothLeService.ACTION_STATE_OFF);
                    context.sendBroadcast(stateIntent);
                    break;
                case BluetoothAdapter.STATE_TURNING_ON:
                    Logger.e("正在开启");
                    break;
                case BluetoothAdapter.STATE_TURNING_OFF:
                    Logger.e("正在关闭");
                    break;
            }
        }
    }
}
